package com.qf.hospital.mapper;

import com.qf.hospital.entity.SysMenu;
import com.qf.hospital.entity.User;
import com.qf.hospital.entity.UserExample;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface SysUserMapper {
    long countByExample(UserExample example);

    int deleteByExample(UserExample example);

    int deleteByPrimaryKey(Integer userId);

    int insert(User record);

    int insertSelective(User record);

    List<User> selectByExample(UserExample example);

    User selectByPrimaryKey(Integer userId);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);


    List<SysMenu> findMenuByUserId(@Param("userId") Integer userId);


    /**
     * 查询当前用户拥有的角色is
     * @param userid
     * @return
     */
    @Select("select ru.rid from sys_user u inner join sys_role_user ru on u.user_id = ru.uid where u.user_id = #{userId} and u.available = 1")
    List<Integer> findRoleByUserId(@Param(value = "userId") Integer userid);

    @Delete("delete from sys_role_user where uid = #{userId}")
    void deleteRoleByUserId(@Param(value = "userId") Integer userid);


    /**
     * 添加用户的角色
     * @param userid
     * @param ids
     * @return
     */
    int saveUserRole(@Param(value = "userId") Integer userid, @Param(value = "roleIds") Integer[] ids);

    @Update("update sys_user set pwd = '9e6cdcb0d94b5e670790186f01526abf' where user_id = #{userid}")
    int updatePwdByUserId(@Param("userid") Integer userid);

    @Update("update sys_user set available = 0 where user_id = #{userid}")
    int updateAvailabeByUserId(@Param(value = "userid") Integer userid);

}